<?
session_start();
//session_register('kart_array');
//$_SESSION['kart_array'] = $_SESSION['kart_array'] ;

$path = '../Mkart/';
include($path."common.php");
include($path."prod_fun.php");

$id_array = $_GET['pid'] ;
$num_array = $_GET['num'] ;
$count_array = $_GET['count'] ;

if(isset($id_array) and isset($count_array) and isset($num_array)){
$sql_count = "select * from product where id = '$id_array' order by id" ;
$result_count = mysql_query($sql_count) ;
$row_count = mysql_fetch_object($result_count) ;
$price_count = $row_count -> price_2 ;

$total_price = $price_count * $count_array ;
$_SESSION['kart_array'][$num_array]["price"] = $total_price ;
$_SESSION['kart_array'][$num_array]['count'] = $count_array ;
}
$kart_list  .= "<form method=post id=frm_list name=frm_list action=\"\">" ;
$kart_list  .= "<table width=500 border=0>" ;
$kart_list  .= "<tr>" ;
$kart_list  .= "<td align=center>"."商品名稱"."</td>" ;
$kart_list  .= "<td align=center width=10%>"."數量"."</td>" ;
$kart_list  .= "<td align=center width=10%>"."小計"."</td>" ;
$kart_list  .= "</tr>" ;
$kart_list  .= "<tr><td colspan=3><hr noshade style=\"border:1px dashed #000000;\"><td></tr>" ;
for($i=0;$i<count($_SESSION['kart_array']);$i++){


$prodid = $_SESSION['kart_array'][$i]["id"] ;
$prodname = $_SESSION['kart_array'][$i]["name"] ;
$prodcount = $_SESSION['kart_array'][$i]["count"] ;
$prodprice = $_SESSION['kart_array'][$i]["price"] ;

$sql = "select * from product where id = '$prodid' order by id" ;
$result = mysql_query($sql) ;
$row = mysql_fetch_object($result) ;
$qty = $row -> pd_count ;

$kart_list  .= "<tr>" ;
$kart_list  .= "<td>".$prodname."</td>" ;
$kart_list  .= "<td align=center><select name=count[$prodid] onchange=\"change_count($prodid,$i,this.value)\">" ;
$kart_list  .= "<option value='$prodcount'>".$prodcount."</option>" ;
for($m=1 ; $m<=$qty ; $m++){
$kart_list  .= "<option value='$m'>".$m."</option>" ;
}
$kart_list  .= "</td>" ;
$kart_list  .= "<td align=center>"."NT$".$prodprice."</td>" ;
$kart_list  .= "</tr>" ;
$kart_list  .= "<tr><td colspan=3><hr noshade style=\"border:1px dashed #000000;\"><td></tr>" ;
}
$kart_list  .= "</table>" ;
$kart_list  .= "</form>" ;

$price_sum  = count_array('price',$_SESSION['kart_array']) ;
$kart_list  .= "<table width=500 border=0>" ;
$kart_list  .= "<tr>" ;
$kart_list  .= "<td align=right width=80%>總價<td>" ;
$kart_list  .= "<td align=left>"."NT$".$price_sum."<td>" ;
$kart_list .= "</tr>";
$kart_list  .= "</table>" ;

//$kart_list  .= $count_array  ;


echo $kart_list ;
?>